package br.senai.sc.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;

/**
 * @author Fernando Marquardt &lt;fernando.marquardt@sc.senai.br&gt;
 * @version $Id: Permissao.java 28 2012-03-07 20:48:20Z fernando.marquardt $
 */
@Entity
@Table(name = "permissao")
@NamedQuery(name = Permissao.PERMISSOES, query = "SELECT p FROM Permissao p")
public class Permissao implements Serializable {

    private static final long serialVersionUID = 1L;

    public static final String PERMISSOES = "PERMISSOES";

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id_permissao")
    private Integer idPermissao;

    @NotBlank
    @Length(max = 150)
    private String descricao;

    private boolean consulta = true;

    private boolean cadastro = false;

    private boolean administracao = false;

    public Permissao() {}

    public Integer getIdPermissao() {
        return idPermissao;
    }

    public void setIdPermissao(Integer idPermissao) {
        this.idPermissao = idPermissao;
    }

    public String getDescricao() {
        return descricao;
    }

    public void setDescricao(String descricao) {
        this.descricao = descricao;
    }

    public boolean isConsulta() {
        return consulta;
    }

    public void setConsulta(boolean consulta) {
        this.consulta = consulta;
    }

    public boolean isCadastro() {
        return cadastro;
    }

    public void setCadastro(boolean cadastro) {
        this.cadastro = cadastro;
    }

    public boolean isAdministracao() {
        return administracao;
    }

    public void setAdministracao(boolean administracao) {
        this.administracao = administracao;
    }

    @Override
    public String toString() {
        return "Permissao [idPermissao=" + idPermissao + ", descricao=" + descricao + ", consulta=" + consulta + ", cadastro=" + cadastro
                + ", administracao=" + administracao + "]";
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((idPermissao == null) ? 0 : idPermissao.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        Permissao other = (Permissao) obj;
        if (idPermissao == null) {
            if (other.idPermissao != null) {
                return false;
            }
        } else if (!idPermissao.equals(other.idPermissao)) {
            return false;
        }
        return true;
    }
}